class Solution {
public:
    bool checkPartitioning(string s) {
        int n = s.size(), cnt = 0;;
        vector<vector<char>> dp(n, vector<char>(n));

        for (int j = 0; j < n; ++j)
        {
            for (int i = j; i >= 0; --i)
            {
                if (i == j)
                    dp[i][j] = 1;
                else
                {
                    if (s[i] == s[j] && (j - i == 1 || dp[i + 1][j - 1] == 1))
                        dp[i][j] = 1;
                }
            }
        }
        for (int j = 1; j < n - 1; j++)
        {
            for (int i = 1; i <= j; i++)
            {
                if (dp[i][j] == 1 && dp[0][i - 1] == 1 && dp[j + 1][n - 1] == 1)
                    return true;
            }
        }

        return false;
    }
};